#!/bin/bash

yum install -y mysql-connector-java;
########
#https://archive.apache.org/dist/hive/hive-3.1.3/
########
wget https://archive.apache.org/dist/hive/hive-2.3.9/apache-hive-2.3.9-bin.tar.gz;
tar -xvf apache-hive-2.3.9-bin.tar.gz;
mv apache-hive-2.3.9-bin /home/hadoop/app;
echo 'HIVE_HOME=/home/hadoop/app/apache-hive-2.3.9-bin' >> /etc/profile;
echo 'export PATH=$HIVE_HOME/bin:$PATH' >> /etc/profile;
source /etc/profile;

cd /home/hadoop/app/apache-hive-2.3.9-bin/lib;
wget http://47.114.163.161:8087/mysql/mysql-connector-java-5.1.49/mysql-connector-java-5.1.49.jar;
wget http://47.114.163.161:8087/mysql/mysql-connector-java-8.0.21.jar
cd /home/hadoop/app/apache-hive-2.3.9-bin/conf;
wget http://47.114.163.161:8087/bigdata/hive/2.3.9/hive-site.xml;
cp hive-env.sh.template hive-env.sh;

echo 'export JAVA_HOME=/usr/java/jdk1.8.0_212' >> /home/hadoop/app/apache-hive-2.3.9-bin/bin/hive-config.sh;
echo 'export HIVE_HOME=/home/hadoop/app/apache-hive-2.3.9-bin' >> /home/hadoop/app/apache-hive-2.3.9-bin/bin/hive-config.sh;
echo 'export HADOOP_HOME=/home/hadoop/app/hadoop-2.6.0-cdh5.7.0' >> /home/hadoop/app/apache-hive-2.3.9-bin/bin/hive-config.sh;

cd /home/hadoop/app/apache-hive-2.3.9-bin/bin;
./schematool -dbType mysql -initSchema;